﻿using GameServer;
using GameServer.Virtual_Objects.Room;
using GameServer.Virtual_Objects.User;
using System;
using System.Collections;

namespace GameServer.Networking.Packets
{
    internal class PACKET_ROOM_UDP : Packet
    {
        public PACKET_ROOM_UDP(virtualUser Sender, ArrayList Users)
        {
            int num;
            int num1;
            int num2;
            object obj;
            bool flag;
            bool flag1;
            base.newPacket(29952);
            base.addBlock(Users.Count);
            foreach (virtualUser user in Users)
            {
                base.addBlock(user.UserID);
                base.addBlock(user.SessionID);
                base.addBlock(user.RoomSlot);
                num = (user.isReady ? 1 : 0);
                base.addBlock(num);
                base.addBlock(user.Room.getSide(user));
                base.addBlock(user.Weapon);
                base.addBlock(user.rKills);
                base.addBlock(user.rDeaths);
                base.addBlock(user.Health);
                base.addBlock(user.Nickname);
                base.addBlock(user.ClanID);
                base.addBlock(user.ClanRank);
                base.addBlock(user.ClanRank);
                base.addBlock(user.uniqID);
                base.addBlock(user.uniqID2);
                base.addBlock(user.uniqIDisCRC);
                num1 = (!user.Room.SuperMaster || user.RoomSlot != user.Room.RoomMasterSlot ? user.Premium : 0);
                base.addBlock(num1);
                num2 = (user.PCItem ? 1 : 0);
                base.addBlock(num2);
                base.addBlock(-1);
                base.addBlock(user.Kills);
                base.addBlock(user.Deaths);
                base.addBlock(user.Health);
                base.addBlock(user.Exp);
                base.addBlock(-1);
                base.addBlock(-1);
                obj = (user.isSpawned ? "1" : user.Class);
                base.addBlock(obj);
                flag = (Sender.nIP != user.nIP ? true : Sender.lIP != user.lIP);
                if (flag)
                {
                    flag1 = (Sender.nIP != user.nIP ? true : Sender.lIP == user.lIP);
                    if (flag1)
                    {
                        base.addBlock(user.nIP);
                    }
                    else
                    {
                        base.addBlock(user.lIP);
                    }
                }
                else
                {
                    base.addBlock(user.IPToInt("127.0.0.1"));
                }
                base.addBlock(user.nPort);
                base.addBlock(user.lIP);
                base.addBlock(user.lPort);
                base.addBlock(0);
            }
        }
    }
}
